<template>
	<view>
		<view class="gt-form-item">
			<view v-if="label" class="gt-form-label-group">
				<view class="row">
					<view class="gt-form-label-left"></view>
					<view v-if="required" class="gt-form-required">*</view>
					<view class="gt-form-label">{{label}}</view>
					<uni-icons v-if="desc" class="gt-form-desc" type="help" size="20" color="#999999"
						@click="showDesc()">
					</uni-icons>
				</view>
			</view>
			<view class="gt-form-body">
				<view class="gt-tab ">
					<view class="gt-tab-btn">
						<view class="gt-tab-row">
							<view v-if="all" @click="changeDefault()" class="gt-tab-item"
								:class="value === '' ?'gt-tab-item-selected':''">
								<text>{{ all || '' }}</text>
							</view>
							<view v-if="list.length > 0" v-for="(row,key) in list" :key="key"
								@click="changeSelected(key,row)" class="gt-tab-item"
								:class="value === row.key ?'gt-tab-item-selected':''">
								<text class="iconfont" :class="row.icon || ''"></text>
								<text>{{ row.val }}</text>
							</view>
						</view>
					</view>
				</view>
				<view v-if="error!== false" class="gt-form-error">{{error}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "gt-select",
		props: {
			value: {
				type: [Number, String],
				default: function() {
					return ''
				}
			},
			all: {
				type: [Number, String],
				default: function() {
					return ''
				}
			},
			list: {
				type: [Array, Object],
				default: function() {
					return {};
				}
			},
			label: {
				type: String,
				default: ''
			},
			field: {
				type: String,
				default: ''
			},
			desc: {
				type: String,
				default: ''
			},
			required: {
				type: [String, Boolean],
				default: ''
			},
			error: {
				type: [String, Boolean],
				default: false
			},
			placeholder: {
				type: String,
				default: '请选择'
			},
			placeholderClass: {
				type: String,
				default: 'placeholderClass'
			},
			leftIcon: {
				type: String,
				default: ''
			},
			rightIcon: {
				type: String,
				default: 'icon-unfold'
			},
			leftText: {
				type: String,
				default: ''
			},
			rightText: {
				type: String,
				default: ''
			}
		},
		created() {},
		data() {
			return {
				selected: ''
			}
		},
		watch: {},
		computed: {},
		methods: {
			changeDefault() {
				this.$emit('change', '');
				this.$emit('clickBack', {
					type: 'search',
					field: this.field
				})
			},
			changeSelected(key, row) {
				if (row.key === this.value) {
					this.$emit('input', '',this.field);
				} else {
					this.$emit('input', row.key,this.field);
				}
				this.$emit('clickBack', {
					type: 'search',
					field: this.field
				})

			},
		}
	}
</script>

<style lang="scss">
	.placeholderClass {
		color: #cccccc
	}
	.gt-tab {}
	
	.gt-tab-bottom-line {
		border-bottom: #EEEEEE solid 1px;
		margin-top: -1px;
	}
	
	.gt-tab-row {
		display: -webkit-box;
		display: -moz-box;
		display: -ms-flexbox;
		display: -webkit-flex;
		display: flex;
		flex-flow: row wrap;
		-webkit-flex-flow: row wrap;
		-ms-flex-flow: row wrap;
		box-sizing: border-box;
	}
	
	.gt-tab-item {
		line-height: 38px;
		padding: 0 15px;
		cursor: pointer;
		border-bottom: 1px solid #eeeeee;
	}
	
	.gt-tab-card {
		.gt-tab-row {
			padding-left: 10px;
		}
		.gt-tab-item {
			border: 1px solid #eeeeee;
			background-color: #fafafa;
			color: #999999;
			margin-left: 5px;
			border-radius: 5px 5px 0 0;
			position: relative;
		}
		.gt-tab-item-selected {
			color: #409EFF;
			background-color: #ffffff;
			border-bottom: 1px solid #ffffff;
		}
	}
	
	.gt-tab-border-card {}
	
	.gt-tab-btn {
		.gt-tab-row {
		}
		.gt-tab-item {
			color: #666666;
			border: 1px solid #eeeeee;
			border-left: none;
			background-color: #fafafa;
			color: #999999;
			border-radius: none;
			position: relative;
		}
		.gt-tab-item:first-child {
			border-left: 1px solid #eeee;
			border-radius: 5px 0 0 5px;
		}
		.gt-tab-item:last-child {
			border-radius: 0 5px 5px 0;
		}
		.gt-tab-item-selected {
			color: #409EFF;
			background-color: #ffffff;
		}
		.gt-tab-bottom-line {
			display: none;
		}
	}
	
	.gt-tab-item-selected {
		color: #409EFF;
		background-color: #ffffff;
		border-bottom: 1px solid #409EFF;
	}
	.gt-form-sm .gt-tab-item{
		
			height: 30px;
			line-height: 30px;
	}
	
	.status-item {
		height: 30px;
		line-height: 30px;
		width: 120px;
		color: #727579;
		border-top-left-radius: 5px;
		border-top-right-radius: 5px;
		position: relative;
	}
	
	.selected-sign {
		color: #409EFF;
		border-bottom: 0px;
		box-sizing: border-box;
		box-shadow: 0px 0px 3px #BBBBBB;
	}
</style>
